package com.hava.demo.springmvc.manytoone.service;

import com.hava.demo.springmvc.manytoone.entity.M2OMany;
import com.hava.demo.springmvc.manytoone.repository.M2OManyRepository;
import com.hava.demo.springmvc.onlyone.repository.OnlyOneRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by zhanpeng on 15-6-15.
 */
@Service
@Transactional
public class M2OManyService {

    //这里必须添加注释，否则会出现NullPointerException
    @Autowired
    private M2OManyRepository one;

    public void create(M2OMany entity)
    {
        one.save(entity);
    }

    public void delete(Long id)
    {
        one.delete(id);
    }

    public void update(M2OMany entity)
    {
        one.save(entity);
    }

    public M2OMany get(Long id)
    {
        return one.findOne(id);
    }

    public List<M2OMany> getAll()
    {
        return (List<M2OMany>)one.findAll();
    }
}
